﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：SYS_UPLOAD_LOG实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class SYS_UPLOAD_LOG
    {
        private decimal? m_dec_i_caozuor;

        private decimal m_dec_i_jlzt;

        private decimal? m_dec_i_type;

        private decimal? m_dec_i_wenjianlx;

        private decimal m_dec_id;

        private DateTime m_DT_d_caozuorq;

        private string m_str_s_wenjianlj;

        private string m_str_s_wenjianmc;

        private string m_str_s_yonghubh;

        /// <summary>
        ///     主键
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        ///     材料类别 1用水2取水
        /// </summary>
        public decimal? I_TYPE
        {
            get { return m_dec_i_type; }
            set { m_dec_i_type = value; }
        }

        /// <summary>
        ///     文件链接地址
        /// </summary>
        public string S_WENJIANLJ
        {
            get { return m_str_s_wenjianlj; }
            set { m_str_s_wenjianlj = value; }
        }

        /// <summary>
        ///     文件类型
        /// </summary>
        public decimal? I_WENJIANLX
        {
            get { return m_dec_i_wenjianlx; }
            set { m_dec_i_wenjianlx = value; }
        }

        /// <summary>
        ///     文件名称
        /// </summary>
        public string S_WENJIANMC
        {
            get { return m_str_s_wenjianmc; }
            set { m_str_s_wenjianmc = value; }
        }

        /// <summary>
        ///     用户编号
        /// </summary>
        public string S_YONGHUBH
        {
            get { return m_str_s_yonghubh; }
            set { m_str_s_yonghubh = value; }
        }

        /// <summary>
        ///     操作人
        /// </summary>
        public decimal? I_CAOZUOR
        {
            get { return m_dec_i_caozuor; }
            set { m_dec_i_caozuor = value; }
        }

        /// <summary>
        ///     操作时间
        /// </summary>
        public DateTime D_CAOZUORQ
        {
            get { return m_DT_d_caozuorq; }
            set { m_DT_d_caozuorq = value; }
        }

        /// <summary>
        ///     记录状态0正常1删除
        /// </summary>
        public decimal I_JLZT
        {
            get { return m_dec_i_jlzt; }
            set { m_dec_i_jlzt = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class SYS_UPLOAD_LOGProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public SYS_UPLOAD_LOGProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据SYS_UPLOAD_LOG实体添加或者修改SYS_UPLOAD_LOG信息
        /// </summary>
        public bool InsertOrUpdate(SYS_UPLOAD_LOG SYS_UPLOAD_LOG, OracleTransaction Transaction)
        {
            if (SYS_UPLOAD_LOG.ID == 0)
                InsertSYS_UPLOAD_LOG(SYS_UPLOAD_LOG, Transaction);
            else
                UpdateSYS_UPLOAD_LOG(SYS_UPLOAD_LOG, Transaction);
            return SYS_UPLOAD_LOG.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据SYS_UPLOAD_LOG实体添加或修改SYS_UPLOAD_LOG信息
        /// </summary>
        public bool InsertOrUpdate(SYS_UPLOAD_LOG SYS_UPLOAD_LOG)
        {
            return InsertOrUpdate(SYS_UPLOAD_LOG, null);
        }


        /// <summary>
        ///     根据SYS_UPLOAD_LOG主键删除SYS_UPLOAD_LOG信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteSYS_UPLOAD_LOG(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelSYS_UPLOAD_LOG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据SYS_UPLOAD_LOG主键删除SYS_UPLOAD_LOG信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteSYS_UPLOAD_LOG(decimal ID)
        {
            return DeleteSYS_UPLOAD_LOG(ID, null);
        }

        /// <summary>
        ///     根据条件删除SYS_UPLOAD_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteSYS_UPLOAD_LOGsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelSYS_UPLOAD_LOGsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除SYS_UPLOAD_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteSYS_UPLOAD_LOGsDynamic(string WhereClause)
        {
            return DeleteSYS_UPLOAD_LOGsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据SYS_UPLOAD_LOG主键选择SYS_UPLOAD_LOG信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>SYS_UPLOAD_LOG信息</returns>
        public SYS_UPLOAD_LOG SelectSYS_UPLOAD_LOG(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelSYS_UPLOAD_LOG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var SYS_UPLOAD_LOG = PopulateSYS_UPLOAD_LOG(rd);
                rd.Close();
                return SYS_UPLOAD_LOG;
            }
            return null;
        }

        /// <summary>
        ///     根据SYS_UPLOAD_LOG主键选择SYS_UPLOAD_LOG信息
        /// </summary>
        /// <returns>SYS_UPLOAD_LOG信息</returns>
        public SYS_UPLOAD_LOG SelectSYS_UPLOAD_LOG(decimal ID)
        {
            return SelectSYS_UPLOAD_LOG(ID, null);
        }

        /// <summary>
        ///     选择所有SYS_UPLOAD_LOG信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有SYS_UPLOAD_LOG信息</returns>
        public DataTable SelectSYS_UPLOAD_LOGsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelSYS_UPLOAD_LOGsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有SYS_UPLOAD_LOG信息
        /// </summary>
        /// <returns>所有SYS_UPLOAD_LOG信息</returns>
        public DataTable SelectSYS_UPLOAD_LOGsAll()
        {
            return SelectSYS_UPLOAD_LOGsAll(null);
        }

        /// <summary>
        ///     根据条件选择SYS_UPLOAD_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>SYS_UPLOAD_LOG信息</returns>
        public DataTable SelectSYS_UPLOAD_LOGsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelSYS_UPLOAD_LOGsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择SYS_UPLOAD_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>SYS_UPLOAD_LOG信息</returns>
        public DataTable SelectSYS_UPLOAD_LOGsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectSYS_UPLOAD_LOGsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择SYS_UPLOAD_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>SYS_UPLOAD_LOG信息</returns>
        public DataTable SelectSYS_UPLOAD_LOGsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelSYS_UPLOAD_LOGsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择SYS_UPLOAD_LOG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>SYS_UPLOAD_LOG信息</returns>
        public DataTable SelectSYS_UPLOAD_LOGsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectSYS_UPLOAD_LOGsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新SYS_UPLOAD_LOG字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateSYS_UPLOAD_LOGsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdSYS_UPLOAD_LOGDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新SYS_UPLOAD_LOG字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateSYS_UPLOAD_LOGsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateSYS_UPLOAD_LOGsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertSYS_UPLOAD_LOG(SYS_UPLOAD_LOG SYS_UPLOAD_LOG, OracleTransaction Transaction)
        {
            var spName = "CS_InsSYS_UPLOAD_LOG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = SYS_UPLOAD_LOG.I_TYPE;
            storedParams[1].Value = SYS_UPLOAD_LOG.S_WENJIANLJ;
            storedParams[2].Value = SYS_UPLOAD_LOG.I_WENJIANLX;
            storedParams[3].Value = SYS_UPLOAD_LOG.S_WENJIANMC;
            storedParams[4].Value = SYS_UPLOAD_LOG.S_YONGHUBH;
            storedParams[5].Value = SYS_UPLOAD_LOG.I_CAOZUOR;
            storedParams[6].Value = SYS_UPLOAD_LOG.D_CAOZUORQ;
            storedParams[7].Value = SYS_UPLOAD_LOG.I_JLZT;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            SYS_UPLOAD_LOG.ID = Convert.ToInt32(storedParams[8].Value);
            return result;
        }

        private bool UpdateSYS_UPLOAD_LOG(SYS_UPLOAD_LOG SYS_UPLOAD_LOG, OracleTransaction Transaction)
        {
            var spName = "CS_UpdSYS_UPLOAD_LOG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = SYS_UPLOAD_LOG.I_TYPE;
            storedParams[1].Value = SYS_UPLOAD_LOG.S_WENJIANLJ;
            storedParams[2].Value = SYS_UPLOAD_LOG.I_WENJIANLX;
            storedParams[3].Value = SYS_UPLOAD_LOG.S_WENJIANMC;
            storedParams[4].Value = SYS_UPLOAD_LOG.S_YONGHUBH;
            storedParams[5].Value = SYS_UPLOAD_LOG.I_CAOZUOR;
            storedParams[6].Value = SYS_UPLOAD_LOG.D_CAOZUORQ;
            storedParams[7].Value = SYS_UPLOAD_LOG.I_JLZT;
            storedParams[8].Value = SYS_UPLOAD_LOG.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private SYS_UPLOAD_LOG PopulateSYS_UPLOAD_LOG(IDataReader dr)
        {
            var SYS_UPLOAD_LOG = new SYS_UPLOAD_LOG();
            SYS_UPLOAD_LOG.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            SYS_UPLOAD_LOG.I_TYPE = dr["I_TYPE"] == DBNull.Value ? null : (decimal?) dr["I_TYPE"];
            SYS_UPLOAD_LOG.S_WENJIANLJ = dr["S_WENJIANLJ"] == DBNull.Value ? null : (string) dr["S_WENJIANLJ"];
            SYS_UPLOAD_LOG.I_WENJIANLX = dr["I_WENJIANLX"] == DBNull.Value ? null : (decimal?) dr["I_WENJIANLX"];
            SYS_UPLOAD_LOG.S_WENJIANMC = dr["S_WENJIANMC"] == DBNull.Value ? null : (string) dr["S_WENJIANMC"];
            SYS_UPLOAD_LOG.S_YONGHUBH = dr["S_YONGHUBH"] == DBNull.Value ? null : (string) dr["S_YONGHUBH"];
            SYS_UPLOAD_LOG.I_CAOZUOR = dr["I_CAOZUOR"] == DBNull.Value ? null : (decimal?) dr["I_CAOZUOR"];
            SYS_UPLOAD_LOG.D_CAOZUORQ = dr["D_CAOZUORQ"] == DBNull.Value
                ? Convert.ToDateTime("1900-1-1")
                : (DateTime) dr["D_CAOZUORQ"];
            SYS_UPLOAD_LOG.I_JLZT = dr["I_JLZT"] == DBNull.Value ? 0 : (decimal) dr["I_JLZT"];
            return SYS_UPLOAD_LOG;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion